//
//  MSItemManager.m
//  MagicSword
//
//  Created by Netease on 15/12/4.
//  Copyright © 2015年 Jonear. All rights reserved.
//

#import "MSItemManager.h"
#import "MSWeaponManager.h"
#import "MSGameManager.h"

@implementation MSItemManager

+ (NSString *)getItemWithType:(MSItemType)type hero:(MSHeroInfo *)hero {
    NSString *message = @"";
    switch (type) {
            //钥匙
        case MSItemType_Key1:
            message = @"黄门已经打开";
            [[MSGameManager shareManager] openDoorWithType:MSItemType_Key1];
            break;
        case MSItemType_Key2:
            message = @"蓝门已经打开";
            [[MSGameManager shareManager] openDoorWithType:MSItemType_Key2];
            break;
        case MSItemType_Key3:
            message = @"红门已经打开";
            [[MSGameManager shareManager] openDoorWithType:MSItemType_Key3];
            break;
        case MSItemType_Key4:
            message = @"绿门已经打开";
            [[MSGameManager shareManager] openDoorWithType:MSItemType_Key4];
            break;
            
            // 血
        case MSItemType_hp1:
            message = [self getUpHP:10 heroInfo:hero];
            break;
        case MSItemType_hp2:
            message = [self getUpHP:30 heroInfo:hero];
            break;
        case MSItemType_hp3:
            message = [self getUpHP:50 heroInfo:hero];
            break;
        case MSItemType_hp4:
            message = [self getUpHP:100 heroInfo:hero];
            break;
            
            // 武器
        case MSItemType_Sword1:
            message = [self getWeapon:MSWeaponModel_1 heroInfo:hero];
            break;
        case MSItemType_Sword2:
            message = [self getWeapon:MSWeaponModel_2 heroInfo:hero];
            break;
        case MSItemType_Sword3:
            message = [self getWeapon:MSWeaponModel_3 heroInfo:hero];
            break;
        case MSItemType_Axe1:
            message = [self getWeapon:MSWeaponModel_4 heroInfo:hero];
            break;
        case MSItemType_Axe2:
            message = [self getWeapon:MSWeaponModel_5 heroInfo:hero];
            break;
        case MSItemType_Axe3:
            message = [self getWeapon:MSWeaponModel_6 heroInfo:hero];
            break;
        case MSItemType_Spear1:
            message = [self getWeapon:MSWeaponModel_7 heroInfo:hero];
            break;
        case MSItemType_Spear2:
            message = [self getWeapon:MSWeaponModel_8 heroInfo:hero];
            break;
        case MSItemType_Spear3:
            message = [self getWeapon:MSWeaponModel_9 heroInfo:hero];
            break;
            
        //宝箱
        case MSItemType_item1:
            message = [self getWeapon:[self randomWeapon] heroInfo:hero];
            break;
            
        default:
            break;
    }
    
    return message;
}

+ (MSWeaponModel)randomWeapon {
    int r = random()%15;
    return (MSWeaponModel)r;
}

+ (NSString *)getWeapon:(MSWeaponModel)type heroInfo:(MSHeroInfo *)hero {
    MSWeaponInfo *weapon = [MSWeaponManager createWeaponWithModel:type];
    NSString *message = nil;
    if ((int)hero.profession == (int)weapon.type && hero.weaponList.count<3) {
        [hero.weaponList addObject:weapon];
        message = [NSString stringWithFormat:@"获得武器 - %@", weapon.name];
    } else {
        [[MSWeaponManager shareManager] addWeapon:weapon];
        message = [NSString stringWithFormat:@"获得武器 - %@, 已放入仓库", weapon.name];
    }
    
    return message;
}

+ (NSString *)getUpHP:(NSInteger)hp heroInfo:(MSHeroInfo *)hero {
    hero.HP += hp;
    if (hero.HP > hero.MaxHP) {
        hero.HP = hero.MaxHP;
    }
    
    return [NSString stringWithFormat:@"获得%d点生命值", hp];
}

@end
